home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Diamond Collection / The Diamond Collection (Software Vault)(Digital Impact).ISO / cdr44 / xlib06p1.zip / XPBITMAP.CPP < prev    next >
C/C++ Source or Header  |  1995-03-15  |  4KB  |  138 lines

  1. #include "xinternl.h"
  2. #include <conio.h>
  3. #include <mem.h>
  4.  
  5. /*==================================================================
  6. XPBITMAP.CPP contains the basic functions for bitmap manipulation.
  7.  
  8. These routines were written initially by Themie Gouthas and
  9. company and modified March 1995 by Victor B. Putz.
  10. ===================================================================*/
  11.  
  12.  
  13. extern int ScrnLogicalByteWidth;
  14. extern BYTE * pbVGABuffer;
  15.  
  16.  
  17. void x_put_masked_pbm(  /* Copy a planar bitmap from SRAM masking */
  18.   xScreenCoord_t X,    /* only non zero pixels to VRAM           */
  19.   xScreenCoord_t Y,
  20.   xPageHandle_t ScrnOffs,
  21.   BYTE * Bitmap)
  22. {
  23.   BYTE * pbSource = Bitmap;
  24.   int iWidth = *pbSource++;
  25.   int iHeight = *pbSource++;
  26.   BYTE * pbDest = pbVGABuffer + ScrnOffs + ( ScrnLogicalByteWidth * Y ) + X / 4;
  27.   BYTE * pbDestCounter = pbDest;
  28.   int iSkip = ScrnLogicalByteWidth - iWidth;
  29.   outp( SC_INDEX, MAP_MASK );
  30.   int iPlane = X & 3;
  31.   int iAdjust = 0;
  32.   for( int iPlaneCounter = 4; iPlaneCounter != 0; --iPlaneCounter ) {
  33.     pbDestCounter = pbDest + iAdjust;
  34.     pbSource = Bitmap + 2 + ( 4 - iPlaneCounter ) * iWidth * iHeight;
  35.       outp( SC_INDEX + 1, 1 << iPlane );
  36.     for ( int iRowCounter = iHeight; iRowCounter != 0; --iRowCounter ) {
  37.         for ( int iWidthCounter = iWidth; iWidthCounter != 0; --iWidthCounter ) {
  38.           BYTE bTemp = *pbSource++;
  39.           if ( bTemp ) {
  40.             *pbDestCounter++ = bTemp;
  41.           }
  42.           else {
  43.             pbDestCounter++;
  44.           }
  45.       }
  46.       pbDestCounter += iSkip;
  47.     }
  48.     iPlane++;
  49.     if ( iPlane == 4 ) {
  50.       iAdjust = 1;
  51.     }
  52.     iPlane &= 3;
  53.   }
  54. }
  55.  
  56. void x_flip_masked_pbm(  /* Copy a planar bitmap from SRAM masking */
  57.   xScreenCoord_t X,     /* only non zero pixels to VRAM. Bitmap   */
  58.   xScreenCoord_t Y,     /* is mirrored.                           */
  59.   xPageHandle_t ScrnOffs,
  60.   BYTE * Bitmap,
  61.   int orientation);
  62.  
  63. void x_put_pbm(         /* Copy a planar bitmap from SRAM to VRAM */
  64.   xScreenCoord_t X,
  65.   xScreenCoord_t Y,
  66.   xPageHandle_t ScrnOffs,
  67.   BYTE * Bitmap
  68. )
  69. {
  70.   BYTE * pbSource = Bitmap;
  71.   int iWidth = *pbSource++;
  72.   int iHeight = *pbSource++;
  73.   BYTE * pbDest = pbVGABuffer + ScrnOffs + ( ScrnLogicalByteWidth * Y ) + X / 4;
  74.   BYTE * pbDestCounter = pbDest;
  75.  
  76.   outp( SC_INDEX, MAP_MASK );
  77.   int iPlane = X & 3;
  78.   int iAdjust = 0;
  79.   for( int iPlaneCounter = 4; iPlaneCounter != 0; --iPlaneCounter ) {
  80.     pbDestCounter = pbDest + iAdjust;
  81.     pbSource = Bitmap + 2 + ( 4 - iPlaneCounter ) * iWidth * iHeight;
  82.       outp( SC_INDEX + 1, 1 << iPlane );
  83.     for ( int iRowCounter = iHeight; iRowCounter != 0; --iRowCounter ) {
  84.       memcpy( pbDestCounter, pbSource, iWidth );
  85.       pbSource += iWidth;
  86.       pbDestCounter += ScrnLogicalByteWidth;
  87.     }
  88.     iPlane++;
  89.     if ( iPlane == 4 ) {
  90.       iAdjust = 1;
  91.     }
  92.     iPlane &= 3;
  93.   }
  94. }
  95.  
  96.  
  97. void x_flip_pbm(         /* Copy a planar bitmap from SRAM to VRAM */
  98.   xScreenCoord_t X,
  99.   xScreenCoord_t Y,
  100.   xPageHandle_t ScrnOffs,
  101.   BYTE * Bitmap,
  102.   int orientation);
  103.  
  104. void x_get_pbm(         /* Copy a planar bitmap from VRAM to SRAM */
  105.   xScreenCoord_t X,
  106.   xScreenCoord_t Y,
  107.   int iNibbleWidth,
  108.   int iHeight,
  109.   xPageHandle_t ScrnOffs,
  110.   BYTE * Bitmap)
  111. {
  112.   BYTE * pbDest = Bitmap;
  113.   *pbDest++ = ( BYTE )iNibbleWidth;
  114.   *pbDest++ = ( BYTE )iHeight;
  115.   BYTE * pbSource = pbVGABuffer + ScrnOffs + ( ScrnLogicalByteWidth * Y ) + X / 4;
  116.   BYTE * pbSourceCounter = pbSource;
  117.   outp( GC_INDEX, READ_MAP );
  118.   int iPlane = X & 3;
  119.     //an adjustment mark for incrementing the start in video memory after
  120.   //we've passed plane 4
  121.   int iAdjust = 0;
  122.   for( int iPlaneCounter = 4; iPlaneCounter != 0; --iPlaneCounter ) {
  123.     pbSourceCounter = pbSource + iAdjust;
  124.     pbDest = Bitmap + 2 + (4 - iPlaneCounter) * iNibbleWidth * iHeight;
  125.       outp( GC_INDEX + 1, iPlane );
  126.     for ( int iRowCounter = iHeight; iRowCounter != 0; --iRowCounter ) {
  127.       memcpy( pbDest, pbSourceCounter, iNibbleWidth );
  128.       pbDest += iNibbleWidth;
  129.       pbSourceCounter += ScrnLogicalByteWidth;
  130.     }
  131.     iPlane++;
  132.     if ( iPlane == 4 ) {
  133.       iAdjust = 1;
  134.     }
  135.     iPlane &= 3;
  136.   }
  137. }
  138.